//
//  xsTextView.m
//  digital_robot_demo
//
//  Created by xskj on 2024/8/29.
//  文字
// @[@"键盘",@"样式"]

#import "xsTextView.h"
  
#define xrandomColor  [UIColor colorWithRed:(arc4random() %255)/255.0f green:(arc4random() %255)/255.0f blue:(arc4random() %255)/255.0f alpha:1.0f]

@interface xsTextView()<UIScrollViewDelegate,UITextFieldDelegate>

@property (nonatomic,assign)NSInteger xsDownloadFontfamilyCout;

@property (nonatomic,strong)NSArray *FontTextBackgroundArray;

@property (nonatomic,assign)BOOL isSetFrame;

@property (nonatomic, strong) UIView *topView;
@property (nonatomic, strong) UIButton *searchButton;
@property (nonatomic, strong) UITextField *topInputTextFeild;
@property (nonatomic, strong)UIView *topInputTextFeildBgView;
@property (nonatomic, strong) UIButton *xsVerifyButton;// 确认


@property (nonatomic, strong) UIScrollView *TopToorBarbuttonsBgScrollView;
@property (nonatomic, strong) NSArray *TopToorBarbuttonsArray;
@property (nonatomic, strong) UIView *TopToorBarButtonBgView;


@property (nonatomic,strong)UIScrollView *xsBottomScrollView;
@property (nonatomic,strong)UIView *xsKeyBordView;// 键盘
@property (nonatomic,strong) UIView *xsStyleView;// 样式
@property (nonatomic,strong) UIView *xsKeyBordStyleLineView;
@property (nonatomic,strong)UIScrollView *xsStyleSubV_FontFamilyScrollV;// 字体类别
@property (nonatomic,strong)UIScrollView *xsStyleSubV_FontBackgroundScrollV;// 文字的背景颜色
@property (nonatomic,strong)UIView *xsColorContourView;// 颜色、描边
@property (nonatomic,strong) UIView *xsColorContourLineView;
// 颜色选项卡
@property (nonatomic,strong)UIScrollView *xsColorContourContentView_colorScrV;
// 描边选项卡
@property (nonatomic,strong)UIScrollView *xsColorContourContentView_ContourScrV;



// 字号
@property (nonatomic,strong)UILabel *xsCharacterLabel;
@property (nonatomic,strong)UIView *xsCharacterView;
@property (nonatomic,strong)UILabel *xsCharacterSliderLabel;

// 描边
@property (nonatomic,strong)UILabel *xsOutlineLabel;
@property (nonatomic,strong)UIView *xsOutlineView;
@property (nonatomic,strong)UILabel *xsOutlineSliderLabel;


@property (nonatomic,strong)NSMutableArray *fontStyleDataMarray;
@property (nonatomic,strong)NSMutableArray *fontFamilyDataMarray;

@end

@implementation xsTextView

- (NSMutableArray *)fontStyleDataMarray{
    if(!_fontStyleDataMarray){
        _fontStyleDataMarray = [[NSMutableArray alloc] init];
    }
    return _fontStyleDataMarray;
}
- (NSMutableArray *)fontFamilyDataMarray{
    if(!_fontFamilyDataMarray){
        _fontFamilyDataMarray = [[NSMutableArray alloc] init];
    }
    return _fontFamilyDataMarray;
}
- (UIView *)xsColorContourLineView{
    if(!_xsColorContourLineView){
        _xsColorContourLineView = [[UIView alloc] init];
        _xsColorContourLineView.backgroundColor = COLOR_White;
    }
    return _xsColorContourLineView;
}
- (UIView *)xsKeyBordStyleLineView{
    if(!_xsKeyBordStyleLineView){
        _xsKeyBordStyleLineView = [[UIView alloc] init];
        _xsKeyBordStyleLineView.backgroundColor = COLOR_White;
    }
    return _xsKeyBordStyleLineView;
}

- (UIView *)TopToorBarButtonBgView{
    if(!_TopToorBarButtonBgView){
        _TopToorBarButtonBgView = [[UIView alloc] init];
        _TopToorBarButtonBgView.backgroundColor = UIColor.blackColor;
    }
    return _TopToorBarButtonBgView;
}

- (UIScrollView *)TopToorBarbuttonsBgScrollView
{
    if(!_TopToorBarbuttonsBgScrollView){
        _TopToorBarbuttonsBgScrollView = [[UIScrollView alloc] init];
        _TopToorBarbuttonsBgScrollView.backgroundColor = UIColor.clearColor;
        
        _TopToorBarbuttonsBgScrollView.delegate = self;
        _TopToorBarbuttonsBgScrollView.pagingEnabled = YES;
        _TopToorBarbuttonsBgScrollView.showsHorizontalScrollIndicator = NO;
    }
    return _TopToorBarbuttonsBgScrollView;
}


#pragma mark 键盘、样式被点击
- (void)xsKeybordStyleButtonEvent:(UIButton *)sender {
    NSInteger selectedIndex = sender.tag;
    NSLog(@"Selected index: %ld", (long)selectedIndex);
    
    if(selectedIndex==0){
        [self.topInputTextFeild becomeFirstResponder];
        
//        bossTopTextClickButtonStyle_keybord = 0,// 键盘
//        bossTopTextClickButtonStyle_style=1,// 样式
        self.ClickButtonStyle = bossTopTextClickButtonStyle_keybord;
    }
    else{
        [self.topInputTextFeild resignFirstResponder];
        self.ClickButtonStyle = bossTopTextClickButtonStyle_style;
    }
    if([self.delegate respondsToSelector:@selector(xsKeybordStyleButtonBeClickEventCallBack:)]){
        [self.delegate xsKeybordStyleButtonBeClickEventCallBack:sender.tag];
    }

    CGFloat xsKeyBordStyleLineViewW = 30.0;
    CGFloat xsKeyBordStyleLineViewH = 3.0;
    CGFloat buttonMargin = (sender.width-xsKeyBordStyleLineViewW)*0.5;
    CGFloat xsKeyBordStyleLineViewX = CGRectGetMinX(sender.frame)+buttonMargin;
    CGFloat xsKeyBordStyleLineViewY = CGRectGetMaxY(sender.frame)-xsKeyBordStyleLineViewH;
    self.xsKeyBordStyleLineView.frame = CGRectMake(xsKeyBordStyleLineViewX, xsKeyBordStyleLineViewY, xsKeyBordStyleLineViewW, xsKeyBordStyleLineViewH);
//    if(selectedIndex==0){// 键盘
//        [self.xsBottomScrollView setContentOffset:CGPointMake(0, 0)];
//    }
//    else{// 样式
//        [self.xsBottomScrollView setContentOffset:CGPointMake(self.xsBottomScrollView.width, 0)];
//    }

}



- (void)xsChangeKeyBordStyleLineViewLocationWithTag:(int)tg{
    
    
    for (UIButton *sender in self.TopToorBarButtonBgView.subviews) {
        if([sender isKindOfClass:[UIButton class]]){
            
            if(sender.tag==tg){
                CGFloat xsKeyBordStyleLineViewW = 30.0;
                CGFloat xsKeyBordStyleLineViewH = 3.0;
                CGFloat buttonMargin = (sender.width-xsKeyBordStyleLineViewW)*0.5;
                CGFloat xsKeyBordStyleLineViewX = CGRectGetMinX(sender.frame)+buttonMargin;
                CGFloat xsKeyBordStyleLineViewY = CGRectGetMaxY(sender.frame)-xsKeyBordStyleLineViewH;
                self.xsKeyBordStyleLineView.frame = CGRectMake(xsKeyBordStyleLineViewX, xsKeyBordStyleLineViewY, xsKeyBordStyleLineViewW, xsKeyBordStyleLineViewH);
                break;
            }
        }
    }
    if(tg==0){
        self.ClickButtonStyle = bossTopTextClickButtonStyle_keybord;
    }
    else{
        self.ClickButtonStyle = bossTopTextClickButtonStyle_style;
    }

}

- (void)updateConstraints{
    [super updateConstraints];
//    
//    __weak __typeof (&*self)weakSelf = self;
    
    NSLog(@"updateConstraints");
    
    
    
    
}


- (UIView *)topView{
    
    if(!_topView){
        _topView = [[UIView alloc] init];
        _topView.backgroundColor = UIColor.clearColor;
    }
    return _topView;
}



- (UIButton *)xsVerifyButton{
    if (!_xsVerifyButton) {
        _xsVerifyButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _xsVerifyButton.backgroundColor = UIColor.clearColor;
        [_xsVerifyButton addTarget:self action:@selector(xsVerifyButtonAction:) forControlEvents:UIControlEventTouchUpInside];
        [_xsVerifyButton setImage:[UIImage imageNamed:@"xsBossgou"] forState:UIControlStateNormal];
//        [_xsVerifyButton setTitle:kLocalizedString(@"确认") forState:UIControlStateNormal];
//        [_xsVerifyButton setTitleColor:COLOR_textBlueColor forState:UIControlStateNormal];
//        [_xsVerifyButton setFont:Font(16)];
    }
    return _xsVerifyButton;
}
- (void)xsVerifyButtonAction:(UIButton *)btn{
    NSLog(@"xsVerifyButtonAction\n\n");
   
    if([self.delegate respondsToSelector:@selector(xsTextViewxsVerifyButtonBeClick:)]){
        [self.delegate xsTextViewxsVerifyButtonBeClick:btn];
    }
    
    [self.topInputTextFeild resignFirstResponder];
}

- (UIButton *)searchButton{
    if (!_searchButton) {
        _searchButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _searchButton.backgroundColor = UIColor.purpleColor;
        [_searchButton addTarget:self action:@selector(searchButtonAction:) forControlEvents:UIControlEventTouchUpInside];
        [_searchButton setImage:[UIImage imageNamed:@"形状 22"] forState:UIControlStateNormal];
        _searchButton.hidden = YES;
    }
    return _searchButton;
}
- (void)searchButtonAction:(UIButton *)btn{
    NSLog(@"searchButtonAction\n\n");
   
    
}
- (UITextField *)topInputTextFeild {
    if (!_topInputTextFeild) {
        _topInputTextFeild = [[UITextField alloc] init];
        _topInputTextFeild.font = Font(15);
        _topInputTextFeild.textColor = COLOR_White;
        _topInputTextFeild.placeholder = kLocalizedString(@"请输入文本(0~50字)");
        _topInputTextFeild.borderStyle = UITextBorderStyleNone;
        //    phoneNumberTF.frame = CGRectMake(25, 20, subViewW, 50);
        //_topInputTextFeild.text = [NSString stringWithFormat:@"%@",contentStr];
        _topInputTextFeild.backgroundColor = UIColor.clearColor;
        //    addFriendInfoLabel.numberOfLines = 2;
        _topInputTextFeild.textAlignment = NSTextAlignmentLeft;
        _topInputTextFeild.clearButtonMode = UITextFieldViewModeAlways;
        _topInputTextFeild.delegate = self;
    }
    return _topInputTextFeild;
}
- (void)bossChangeTopInputTextFeildPlaceholderWithbossTopTextPlaceholdType:(bossTopTextPlaceholdType )topPlaceholderTyp{
    
    if(topPlaceholderTyp==TopTextPlaceholdType_text){
        _topInputTextFeild.placeholder = kLocalizedString(@"请输入文本(0~50字)");
    }
    else if(topPlaceholderTyp==TopTextPlaceholdType_tile){
        _topInputTextFeild.placeholder = kLocalizedString(@"请输入标题");
    }
    else if(topPlaceholderTyp==TopTextPlaceholdType_Subtitles){
        _topInputTextFeild.placeholder = kLocalizedString(@"请输入视频文案(10~800字)");
    }
    else{
        _topInputTextFeild.placeholder = kLocalizedString(@"请输入文本(0~50字)");
    }

}
- (UIView *)topInputTextFeildBgView {
    if (!_topInputTextFeildBgView) {
        _topInputTextFeildBgView = [[UIView alloc] init];
    }
    return _topInputTextFeildBgView;
}
- (UIScrollView *)xsBottomScrollView{
    if(!_xsBottomScrollView){
        _xsBottomScrollView = [[UIScrollView alloc] init];
        _xsBottomScrollView.backgroundColor = UIColor.clearColor;
        _xsBottomScrollView.showsVerticalScrollIndicator = NO;
        _xsBottomScrollView.showsHorizontalScrollIndicator = NO;
        _xsBottomScrollView.pagingEnabled = YES;
        _xsBottomScrollView.delegate = self;
    }
    return _xsBottomScrollView;
}


- (UIView *)xsKeyBordView{
    if(!_xsKeyBordView){
        _xsKeyBordView = [[UIView alloc] init];
        _xsKeyBordView.backgroundColor = UIColor.clearColor;
    }
    return _xsKeyBordView;
}
- (UIView *)xsStyleView{
    if(!_xsStyleView){
        _xsStyleView = [[UIView alloc] init];
        _xsStyleView.backgroundColor = UIColor.clearColor;
    }
    return _xsStyleView;
}


//// 字体类别
- (UIScrollView *)xsStyleSubV_FontFamilyScrollV
{
    if(!_xsStyleSubV_FontFamilyScrollV){
        _xsStyleSubV_FontFamilyScrollV = [[UIScrollView alloc] init];
        _xsStyleSubV_FontFamilyScrollV.backgroundColor = UIColor.clearColor;
        _xsStyleSubV_FontFamilyScrollV.showsVerticalScrollIndicator = NO;
        _xsStyleSubV_FontFamilyScrollV.showsHorizontalScrollIndicator = NO;
    }
    return _xsStyleSubV_FontFamilyScrollV;
}
// 字体样式
- (UIScrollView *)xsStyleSubV_FontBackgroundScrollV
{
    if(!_xsStyleSubV_FontBackgroundScrollV){
        _xsStyleSubV_FontBackgroundScrollV = [[UIScrollView alloc] init];
        _xsStyleSubV_FontBackgroundScrollV.backgroundColor = UIColor.clearColor;
        _xsStyleSubV_FontBackgroundScrollV.showsVerticalScrollIndicator = NO;
        _xsStyleSubV_FontBackgroundScrollV.showsHorizontalScrollIndicator = NO;
    }
    return _xsStyleSubV_FontBackgroundScrollV;
}

#pragma mark 创建字体风格
- (void)xsCreateFontFamilyViewWithArray:(NSArray*)btnsArray{
    
    CGFloat margin10 = 10;
//    NSArray *btnsArray = @[@"猫垦伸进黑",@"思源黑体",@"思源宋体",@"思源唐体",@"思源明体",@"思源元体",@"北欧元体",@"猫垦伸进黑",@"思源黑体",@"思源宋体",@"思源唐体",@"思源明体",@"思源元体",@"北欧元体"];;
    UIFont *btnFont = [UIFont systemFontOfSize:16];
    UIButton *lastButton;
    // 添加按钮到滚动视图
    for (int i = 0; i < btnsArray.count; i++) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        
        xsFontFamilyData *familyMd = btnsArray[i];
        
        
        if(!familyMd.isNotFont){
            
            NSString *buttonTitleStr = familyMd.fontNameWindows;
            CGFloat buttonW = [buttonTitleStr calculateWidth:btnFont withHeight:40]+25.0;
            //        button.frame = CGRectMake(i * buttonW, 0, buttonW, 40);
            if(lastButton){
                button.frame = CGRectMake(CGRectGetMaxX(lastButton.frame)+margin10, 2.5, buttonW, 30);
                
            }
            else{
                button.frame = CGRectMake(0, 2.5, buttonW, 30);
            }
            button.backgroundColor = UIColor.blackColor;//xrandomColor;
            [button setTitle:buttonTitleStr forState:UIControlStateNormal];
            [button setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
            button.font = btnFont;
            [button addTarget:self action:@selector(xsFontFamilyButtonEvent:) forControlEvents:UIControlEventTouchUpInside];
            button.tag = familyMd.Id;
            [self.xsStyleSubV_FontFamilyScrollV addSubview:button];
            button.layer.borderWidth = 1.0;
            button.layer.borderColor = UIColor.clearColor.CGColor;
            button.layer.cornerRadius = 3.0;
            button.layer.masksToBounds = YES;
            lastButton = button;
        }
        else{
            button.frame = CGRectMake(0, 2.5, 30, 30);
            button.backgroundColor = UIColor.blackColor;//xrandomColor;
            [button setImage:[UIImage imageNamed:familyMd.xsDefaultLocalImageStr] forState:UIControlStateNormal];
            [button addTarget:self action:@selector(xsFontFamilyButtonEvent:) forControlEvents:UIControlEventTouchUpInside];
            button.tag = familyMd.Id;
            [self.xsStyleSubV_FontFamilyScrollV addSubview:button];
            button.layer.borderWidth = 1.0;
            button.layer.borderColor = UIColor.clearColor.CGColor;
            button.layer.cornerRadius = 3.0;
            button.layer.masksToBounds = YES;
            lastButton = button;
        }

    }
    self.xsStyleSubV_FontFamilyScrollV.contentSize = CGSizeMake(CGRectGetMaxX(lastButton.frame)+10, 0);
}
- (void)xsFontFamilyButtonEvent:(UIButton *)sender{
    NSLog(@"xsFontFamilyButtonEvent--sender.tag==%ld",sender.tag);
    
    for (UIButton *tempButton in self.xsStyleSubV_FontFamilyScrollV.subviews) {
        if([tempButton isKindOfClass:[UIButton class]]){
            if(tempButton.tag!=sender.tag){
                tempButton.layer.borderWidth = 1.0;
                tempButton.layer.borderColor = UIColor.clearColor.CGColor;
                tempButton.layer.cornerRadius = 3.0;
                tempButton.layer.masksToBounds = YES;
            }
            else{
                tempButton.layer.borderWidth = 1.0;
                tempButton.layer.borderColor = UIColor.blueColor.CGColor;
                tempButton.layer.cornerRadius = 3.0;
                tempButton.layer.masksToBounds = YES;
            }
        }
    }
    
    for (xsFontFamilyData *tempFontMd in self.fontFamilyDataMarray) {
        if(sender.tag==tempFontMd.Id){
            if([self.delegate respondsToSelector:@selector(xsTexViewFontFamilyEvent:)]){
                [self.delegate xsTexViewFontFamilyEvent:tempFontMd];
            }
            break;
        }
    }
}


#pragma mark 文字的描边图片事件
- (void)xsCreateFontTextBackgroundScrollViewWithArray:(NSArray*)btnsArray{
    
    CGFloat margin10 = 10;
//    NSMutableArray *xsStyleButtonsArray = [NSMutableArray new];
//    for (int qq = 0; qq<16; qq++) {
//        [xsStyleButtonsArray addObject:[NSString stringWithFormat:@"style-%d",qq+1]];
//    }
    
    //UIFont *btnFont = [UIFont systemFontOfSize:16];
    UIButton *lastButton;
    // 添加按钮到滚动视图
    for (int i = 0; i < btnsArray.count; i++) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        
        xsFontStyleData *tempFontMd = btnsArray[i];;
        //NSString *hexColorStr =
        
        CGFloat buttonW = 30.0;//[buttonTitleStr calculateWidth:btnFont withHeight:40]+25.0;
        
        if(!tempFontMd.isNotFont){
            
    //        button.frame = CGRectMake(i * buttonW, 0, buttonW, 40);
            if(lastButton){
                button.frame = CGRectMake(CGRectGetMaxX(lastButton.frame)+margin10, 2.5, buttonW, 30);
            }
            else{
                button.frame = CGRectMake(0, 2.5, buttonW, 30);
            }
            //button.backgroundColor = [UIColor xsColorwithHexString:hexColorStr Alpha:1.0];
            
            
            NSData *urlImageData =  [[SDImageCache sharedImageCache]diskImageDataForKey:tempFontMd.image];
            if(urlImageData){
    //            weakSelf.iconImageView.image = ;
    //            [button sd_setImageWithURL:[NSURL URLWithString:tempFontMd.image] forState:UIControlStateNormal];
                [button setImage:[UIImage imageWithData:urlImageData] forState:UIControlStateNormal];
            }
            else{
                [[SDWebImageDownloader sharedDownloader] downloadImageWithURL:[NSURL URLWithString:tempFontMd.image] options:SDWebImageDownloaderLowPriority progress:^(NSInteger receivedSize, NSInteger expectedSize, NSURL * _Nullable targetURL) {
                    
                } completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, BOOL finished) {
                        if (image) {
                            [[SDImageCache sharedImageCache] storeImageDataToDisk:data forKey:tempFontMd.image];
                            
                            // 图片下载成功，将其设置到UIImageView中
                            dispatch_async(dispatch_get_main_queue(), ^{
                                [button setImage:image forState:UIControlStateNormal];
                            });
                        } else {
                            // 处理错误
                            NSLog(@"Error downloading image: %@", error);
                        }
                }];
            }
        }
        else{
            button.frame = CGRectMake(0, 2.5, buttonW, 30);
            
            [button setImage:[UIImage imageNamed:tempFontMd.xsDefaultLocalImageStr] forState:UIControlStateNormal];
        }
        
        
        
        
//        [button setTitle:xsStyleButtonsArray[i] forState:UIControlStateNormal];
//        [button setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
//        button.font = btnFont;
        [button addTarget:self action:@selector(xsFontStyleButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
        button.tag = i;
        [self.xsStyleSubV_FontBackgroundScrollV addSubview:button];
        button.layer.cornerRadius = 3.0;
        button.layer.masksToBounds = YES;
        button.selected = NO;
        lastButton = button;
    }
    self.xsStyleSubV_FontBackgroundScrollV.contentSize = CGSizeMake(CGRectGetMaxX(lastButton.frame)+10, 0);
}

#pragma mark 文字的描边图片事件
- (void)xsFontStyleButtonClicked:(UIButton *)sender{
    NSLog(@"xsStyleButtonClicked--sender.tag==%ld",sender.tag);
    
    sender.selected = !sender.selected;
    
    for (UIButton *tempButton in self.xsStyleSubV_FontBackgroundScrollV.subviews) {
        if([tempButton isKindOfClass:[UIButton class]]){
            if(tempButton.tag!=sender.tag){
                tempButton.layer.borderWidth = 1.0;
                tempButton.layer.borderColor = UIColor.clearColor.CGColor;
                tempButton.layer.cornerRadius = 3.0;
                tempButton.layer.masksToBounds = YES;
            }
            else{
                tempButton.layer.borderWidth = 1.0;
                tempButton.layer.borderColor = UIColor.blueColor.CGColor;
                tempButton.layer.cornerRadius = 3.0;
                tempButton.layer.masksToBounds = YES;
            }
        }
    }
        //xsFontStyleData
    
    if(sender.tag<self.fontStyleDataMarray.count){
        xsFontStyleData *tempFontMd = self.fontStyleDataMarray[sender.tag];
        
        if([self.delegate respondsToSelector:@selector(xsTexViewFontBackgroundEvent:)]){
            [self.delegate xsTexViewFontBackgroundEvent:tempFontMd];
        }
    }
    
    
}



// 颜色描边
- (UIView *)xsColorContourView{
    if(!_xsColorContourView){
        _xsColorContourView = [[UIView alloc] init];
        _xsColorContourView.backgroundColor = UIColor.clearColor;
    }
    return _xsColorContourView;
}

- (instancetype)initWithButtonTitles:(NSArray *)buttonTitles{
    
    if (self = [super init]) {
        self.backgroundColor = UIColor.blackColor;
        
        self.xsDownloadFontfamilyCout = 0;
        
        self.FontTextBackgroundArray = [UIColor get84Color];
        self.isSetFrame = NO;
        [self addSubview:self.topView];
        
        [self.topView addSubview:self.searchButton];
        [self.topView addSubview:self.topInputTextFeildBgView];
        [self.topInputTextFeildBgView addSubview:self.topInputTextFeild];
        [self addSubview:self.xsVerifyButton];
        
        [self addSubview:self.TopToorBarbuttonsBgScrollView];
            
        [self.TopToorBarbuttonsBgScrollView addSubview:self.TopToorBarButtonBgView];
        [self.TopToorBarButtonBgView addSubview:self.xsKeyBordStyleLineView];
        
            
            // 创建按钮数组
        self.TopToorBarbuttonsArray = buttonTitles;//@[@"Tab1", @"Tab2", @"Tab3"];
            
        [self addSubview:self.xsBottomScrollView];
        [self.xsBottomScrollView addSubview:self.xsStyleView];
        [self.xsBottomScrollView addSubview:self.xsKeyBordView];
        
        
        [self.xsStyleView addSubview:self.xsStyleSubV_FontFamilyScrollV];
        [self.xsStyleView addSubview:self.xsStyleSubV_FontBackgroundScrollV];
        [self.xsStyleView addSubview:self.xsColorContourView];// 添加颜色描边
        [self.xsColorContourView addSubview:self.xsColorContourLineView];
        
        
    }
    return self;
}


-(void)layoutSubviews{
    [super layoutSubviews];
    //_recorder.preViewLayer.frame = self.frame;
    
    NSLog(@"layoutSubviews--self.bounds==%@",NSStringFromCGRect(self.bounds));
    
    //[self xsSetFrame];
}

- (void)xsSetFrame{
    
    if(self.isSetFrame){
        
        return;
    }
    
    self.isSetFrame = YES;
    
    CGFloat margin10 = 10;
    [self.topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(margin10);
        make.top.equalTo(self.mas_top);//.offset(10);
        make.right.equalTo(self.mas_right).offset(-margin10);
        make.height.mas_equalTo(50);
    }];
    
    [self.searchButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.topView.mas_left);//.offset(10);
        make.centerY.equalTo(self.topView.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(35, 35));
    }];
    

    
    [self.topInputTextFeildBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.left.right.equalTo(self.topView);
        make.height.mas_equalTo(35);
//        make.centerY.equalTo(self.topView);
    }];
    self.topInputTextFeildBgView.backgroundColor = COLOR_BossIPViewDanGrayColor;//UIColor.lightGrayColor;
    [self.topInputTextFeild mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.topView);
        make.left.equalTo(self.topInputTextFeildBgView.mas_left).offset(margin10);
        make.right.equalTo(self.topView.mas_right).offset(-margin10);
        make.height.mas_equalTo(35);
//        make.centerY.equalTo(self.topView);
    }];
    self.topInputTextFeildBgView.layer.cornerRadius = 6.0;
    self.topInputTextFeildBgView.layer.masksToBounds = YES;
    NSMutableAttributedString *topInputTextFeildAttributedPlaceho = [[NSMutableAttributedString alloc] initWithString:kLocalizedString(@"请输入文本(0~50字)")attributes:@{NSFontAttributeName:Font(15),NSForegroundColorAttributeName:UIColor.lightGrayColor}];
    self.topInputTextFeild.attributedPlaceholder = topInputTextFeildAttributedPlaceho;
    
    
    [self.xsVerifyButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.topView.mas_right);//.offset(10);
        make.top.equalTo(self.topView.mas_bottom).offset(12.5);
        make.size.mas_equalTo(CGSizeMake(35, 35));
    }];
    
    self.TopToorBarbuttonsBgScrollView.frame = CGRectMake(0, 50+10, self.bounds.size.width-margin10-35.0-margin10, 40);
    
    
    
UIFont *btnFont = [UIFont systemFontOfSize:16];
UIButton *lastButton;
// 添加按钮到滚动视图
for (int i = 0; i < self.TopToorBarbuttonsArray.count; i++) {
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];

    NSString *buttonTitleStr = self.TopToorBarbuttonsArray[i];

    CGFloat buttonW = [buttonTitleStr calculateWidth:btnFont withHeight:40]+25.0;

//        button.frame = CGRectMake(i * buttonW, 0, buttonW, 40);
    if(lastButton){
        button.frame = CGRectMake(CGRectGetMaxX(lastButton.frame), 0, buttonW, 40);



    }
    else{
        button.frame = CGRectMake(0, 0, buttonW, 40);


        CGFloat xsKeyBordStyleLineViewW = 30.0;
        CGFloat xsKeyBordStyleLineViewH = 3.0;
        CGFloat buttonMargin = (buttonW-xsKeyBordStyleLineViewW)*0.5;
        CGFloat xsKeyBordStyleLineViewX = CGRectGetMinX(button.frame)+buttonMargin;
        CGFloat xsKeyBordStyleLineViewY = CGRectGetMaxY(button.frame)-xsKeyBordStyleLineViewH;
        self.xsKeyBordStyleLineView.frame = CGRectMake(xsKeyBordStyleLineViewX, xsKeyBordStyleLineViewY, xsKeyBordStyleLineViewW, xsKeyBordStyleLineViewH);
    }
    button.backgroundColor = UIColor.clearColor;//xrandomColor;
    [button setTitle:buttonTitleStr forState:UIControlStateNormal];
    [button setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
    button.font = btnFont;
    [button addTarget:self action:@selector(xsKeybordStyleButtonEvent:) forControlEvents:UIControlEventTouchUpInside];
    [button setTag:i];
    [self.TopToorBarButtonBgView addSubview:button];
    lastButton = button;
}
    self.ClickButtonStyle = bossTopTextClickButtonStyle_keybord;
    
// 设置内容视图的尺寸
self.TopToorBarButtonBgView.frame = CGRectMake(0, 0, CGRectGetMaxX(lastButton.frame), 40);
self.TopToorBarbuttonsBgScrollView.contentSize = self.TopToorBarButtonBgView.frame.size;
    
    

    
    CGFloat xsBottomScrollViewW = self.frame.size.width-2*margin10;
    
    CGFloat xsBottomScrollViewY = CGRectGetMaxY(self.TopToorBarbuttonsBgScrollView.frame)+10;
    CGFloat xsBottomScrollViewH = self.frame.size.height-xsBottomScrollViewY-margin10;
    CGFloat xsBottomScrollViewX = 0;
    [self.xsBottomScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(margin10);
        make.top.equalTo(self.TopToorBarbuttonsBgScrollView.mas_bottom).offset(margin10);
        make.width.mas_equalTo(xsBottomScrollViewW);
        make.height.mas_equalTo(xsBottomScrollViewH);
    }];
    self.xsBottomScrollView.contentSize = CGSizeMake(xsBottomScrollViewW*2.0, 0);
    [self.xsBottomScrollView setContentOffset:CGPointMake(xsBottomScrollViewW, 0)];
    self.xsBottomScrollView.scrollEnabled = NO;
    
    self.xsKeyBordView.frame = CGRectMake(0, 0, xsBottomScrollViewW, xsBottomScrollViewH);
    self.xsStyleView.frame = CGRectMake(xsBottomScrollViewW, 0, xsBottomScrollViewW, xsBottomScrollViewH);
    
    self.xsStyleSubV_FontFamilyScrollV.frame = CGRectMake(0, margin10, xsBottomScrollViewW, 35);
    
    self.xsStyleSubV_FontBackgroundScrollV.frame = CGRectMake(0, CGRectGetMaxY(self.xsStyleSubV_FontFamilyScrollV.frame)+margin10, xsBottomScrollViewW, 35);
    
    
//    self.xsStyleSubV_FontFamilyScrollV.backgroundColor = UIColor.clearColor;
//    self.xsStyleSubV_FontBackgroundScrollV.backgroundColor = UIColor.clearColor;
    
    
    CGFloat xsColorContourViewW = xsBottomScrollViewW;
    CGFloat xsColorContourViewH = 95;
    CGFloat xsColorContourViewY = CGRectGetMaxY(self.xsStyleSubV_FontBackgroundScrollV.frame)+margin10;
    
    //颜色描边
    self.xsColorContourView.frame = CGRectMake(0, xsColorContourViewY, xsColorContourViewW, xsColorContourViewH);
    self.xsColorContourView.backgroundColor = UIColor.clearColor;

    [self createColorContourViewSubView];// 创建颜色描边子view
    
////////////////////  字号  //////////////////////////////
    CGFloat xsCharacterLabelY = CGRectGetMaxY(self.xsColorContourView.frame)+margin10;
    UILabel *xsCharacterLabel = [[UILabel alloc] initWithFrame:CGRectMake(margin10, xsCharacterLabelY, 42, 35)];
    xsCharacterLabel.backgroundColor = UIColor.clearColor;
    xsCharacterLabel.font = Font(16);
    xsCharacterLabel.textColor = COLOR_White;
    xsCharacterLabel.numberOfLines = 1;
    xsCharacterLabel.text = kLocalizedString(@"字号");
    xsCharacterLabel.textAlignment = NSTextAlignmentLeft;
    [self.xsStyleView addSubview:xsCharacterLabel];
//    [xsCharacterLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(self.xsColorContourView.mas_left);
//        make.top.equalTo(self.xsColorContourView.mas_bottom).offset(margin10);
//        make.height.mas_equalTo(35);
//        make.width.mas_equalTo(42);
//    }];
    self.xsCharacterLabel = xsCharacterLabel;
    
    
    CGFloat xsCharacterViewX = CGRectGetMaxX(xsCharacterLabel.frame)+margin10;
    CGFloat xsCharacterViewW = self.xsColorContourView.width-xsCharacterViewX-margin10;
    CGFloat xsCharacterViewY = xsCharacterLabelY;
    UIView *xsCharacterView = [[UIView alloc] initWithFrame:CGRectMake(xsCharacterViewX, xsCharacterViewY, xsCharacterViewW, 35)];
    xsCharacterView.backgroundColor = UIColor.clearColor;
    [self.xsStyleView addSubview:xsCharacterView];
    self.xsCharacterView = xsCharacterView;
    
    CGFloat xsCharacterSliderLabelW = 40;
    CGFloat xsCharacterSliderLabelX = xsCharacterView.width-xsCharacterSliderLabelW;
    UILabel *xsCharacterSliderLabel = [[UILabel alloc] initWithFrame:CGRectMake(xsCharacterSliderLabelX, 0, xsCharacterSliderLabelW, xsCharacterView.height)];
    xsCharacterSliderLabel.backgroundColor = UIColor.clearColor;
    xsCharacterSliderLabel.font = Font(16);
    xsCharacterSliderLabel.textColor = COLOR_textWhiteColor;
    xsCharacterSliderLabel.numberOfLines = 1;
    xsCharacterSliderLabel.text = kLocalizedString(@"16");
    xsCharacterSliderLabel.textAlignment = NSTextAlignmentCenter;
    [xsCharacterView addSubview:xsCharacterSliderLabel];
    self.xsCharacterSliderLabel = xsCharacterSliderLabel;
    
    
    CGFloat xsCharacterSliderW = CGRectGetMinX(xsCharacterSliderLabel.frame)-10;
    // 创建 UISlider
    UISlider *xsCharacterSlider = [[UISlider alloc] initWithFrame:CGRectMake(0.0, 7.5, xsCharacterSliderW, 20.0)];
    xsCharacterSlider.minimumValue = 14;
    xsCharacterSlider.maximumValue = 40;
    xsCharacterSlider.value = 16;
    [xsCharacterSlider addTarget:self action:@selector(xsCharacterSliderChangeEvent:) forControlEvents:UIControlEventValueChanged];
       // 将 slider 添加到视图
    [xsCharacterView addSubview:xsCharacterSlider];
//////////////////////  字号 /////////////////////
    
    
/////////////// 描边 ///////////////////////////////
    CGFloat xsOutlineLabelY = CGRectGetMaxY(self.xsColorContourView.frame)+margin10;
    UILabel *xsOutlineLabel = [[UILabel alloc] initWithFrame:CGRectMake(margin10, xsOutlineLabelY, 42, 35)];
    xsOutlineLabel.backgroundColor = UIColor.clearColor;
    xsOutlineLabel.font = Font(16);
    xsOutlineLabel.textColor = COLOR_White;
    xsOutlineLabel.numberOfLines = 1;
    xsOutlineLabel.text = kLocalizedString(@"描边");
    xsOutlineLabel.textAlignment = NSTextAlignmentLeft;
    [self.xsStyleView addSubview:xsOutlineLabel];
    //    [xsOutlineLabel mas_makeConstraints:^(MASConstraintMaker *make) {
    //        make.left.equalTo(self.xsColorContourView.mas_left);
    //        make.top.equalTo(self.xsColorContourView.mas_bottom).offset(margin10);
    //        make.height.mas_equalTo(35);
    //        make.width.mas_equalTo(42);
    //    }];
    self.xsOutlineLabel = xsOutlineLabel;


    CGFloat xsOutlineViewX = CGRectGetMaxX(xsOutlineLabel.frame)+margin10;
    CGFloat xsOutlineViewW = self.xsColorContourView.width-xsOutlineViewX-margin10;
    CGFloat xsOutlineViewY = xsOutlineLabelY;
    UIView *xsOutlineView = [[UIView alloc] initWithFrame:CGRectMake(xsOutlineViewX, xsOutlineViewY, xsOutlineViewW, 35)];
    xsOutlineView.backgroundColor = UIColor.clearColor;
    [self.xsStyleView addSubview:xsOutlineView];
    self.xsOutlineView = xsOutlineView;

    CGFloat xsOutlineSliderLabelW = 40;
    CGFloat xsOutlineSliderLabelX = xsOutlineView.width-xsOutlineSliderLabelW;
    UILabel *xsOutlineSliderLabel = [[UILabel alloc] initWithFrame:CGRectMake(xsOutlineSliderLabelX, 0, xsOutlineSliderLabelW, xsOutlineView.height)];
    xsOutlineSliderLabel.backgroundColor = UIColor.clearColor;
    xsOutlineSliderLabel.font = Font(16);
    xsOutlineSliderLabel.textColor = COLOR_textWhiteColor;
    xsOutlineSliderLabel.numberOfLines = 1;
    xsOutlineSliderLabel.text = kLocalizedString(@"0");
    xsOutlineSliderLabel.textAlignment = NSTextAlignmentCenter;
    [xsOutlineView addSubview:xsOutlineSliderLabel];
    self.xsOutlineSliderLabel = xsOutlineSliderLabel;


    CGFloat xsOutlineSliderW = CGRectGetMinX(xsOutlineSliderLabel.frame)-10;
    // 创建 UISlider
    UISlider *xsOutlineSlider = [[UISlider alloc] initWithFrame:CGRectMake(0.0, 7.5, xsOutlineSliderW, 20.0)];
    xsOutlineSlider.minimumValue = 0;
    xsOutlineSlider.maximumValue = 15;
    xsOutlineSlider.value = 0;
    [xsOutlineSlider addTarget:self action:@selector(xsOutlineSliderChangeEvent:) forControlEvents:UIControlEventValueChanged];
       // 将 slider 添加到视图
    [xsOutlineView addSubview:xsOutlineSlider];
    
    // 描边
    self.xsOutlineLabel.hidden = YES;
    self.xsOutlineView.hidden = YES;
    
    // 字号
    self.xsCharacterLabel.hidden = NO;
    self.xsCharacterView.hidden = NO;
    
//////////////// 描边 //////////////////////////////
    
//    [xsCharacterSlider setThumbTintColor:UIColor.grayColor];
//    [xsCharacterSlider setMinimumTrackTintColor:UIColor.blueColor];
//    [xsCharacterSlider setMaximumTrackTintColor:UIColor.lightGrayColor];
    
    [self getFontStyleListData];//获取文字的描边图片列表数据
    [self getFontFamilyListData];//获取字体风格列表
    
    
    //self.xsStyleView.backgroundColor = UIColor.redColor;
    
    //颜色选项卡的子view
    [self createxsColorContourContentView_colorScrVSubViews];
    //描边选项卡的子view
    [self createxsColorContourContentView_ContourScrVSubViews];
    
    
}
#pragma mark 字号大小改变
- (void)xsCharacterSliderChangeEvent:(UISlider *)sender{
    NSLog(@"xsCharacterSliderChangeEvent");
    
    CGFloat tempValueF = sender.value;
    int tempValueInt = (int)tempValueF;
    self.xsCharacterSliderLabel.text = [NSString stringWithFormat:@"%d",tempValueInt];
    
    if([self.delegate respondsToSelector:@selector(xsTexViewTextSizeEvent:)]){
        [self.delegate xsTexViewTextSizeEvent:tempValueF];
    }
}
#pragma mark 描边大小改变
- (void)xsOutlineSliderChangeEvent:(UISlider *)sender{
    NSLog(@"xsOutlineSliderChangeEvent");
    
    CGFloat tempValueF = sender.value;
    int tempValueInt = (int)tempValueF;
    self.xsOutlineSliderLabel.text = [NSString stringWithFormat:@"%d",tempValueInt];
    
    if([self.delegate respondsToSelector:@selector(xsTexViewTextContourOutlineSizeEvent:)]){
        [self.delegate xsTexViewTextContourOutlineSizeEvent:tempValueF];
    }
}



//+ (UIColor *)ColorWithHexString:(NSString *)color {
//    return [UIColor ColorwithHexString:color Alpha:-1];
//}
#pragma mark 创建颜色描边的子view
- (void)createColorContourViewSubView
{
    
    CGFloat margin5 = 5;
    XSButton *xsColorButton = [XSButton buttonWithType:UIButtonTypeCustom];
    xsColorButton.backgroundColor = UIColor.clearColor;
    [xsColorButton setTitle:@"颜色" forState:UIControlStateNormal];
    [xsColorButton setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
    xsColorButton.tag = 0;
    [self.xsColorContourView addSubview:xsColorButton];
   
//    [xsColorButton addTapRunWithBlock:^(XSButton * _Nonnull YSBtn) {
//        NSLog(@"xsColorButton addTapRunWithBlock");
//    }];
    [xsColorButton addTarget:self action:@selector(ColorContourButtonEvent:) forControlEvents:UIControlEventTouchUpInside];
    [xsColorButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.xsColorContourView.mas_left);//.offset(15);
        make.top.equalTo(self.xsColorContourView.mas_top).offset(margin5);
        make.width.mas_equalTo(40);
        make.height.mas_equalTo(30);
    }];
    
    [self.xsColorContourLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.xsColorContourView.mas_left).offset(5);
        make.bottom.equalTo(xsColorButton.mas_bottom).offset(3);
        make.width.mas_equalTo(30);
        make.height.mas_equalTo(3);
    }];
    
    XSButton *ContourButton = [XSButton buttonWithType:UIButtonTypeCustom];
    ContourButton.backgroundColor = UIColor.clearColor;
    [ContourButton setTitle:@"描边" forState:UIControlStateNormal];
    [ContourButton setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
    ContourButton.tag = 1;
    [self.xsColorContourView addSubview:ContourButton];
   
   
    
//    [ContourButton addTapRunWithBlock:^(XSButton * _Nonnull YSBtn) {
//        NSLog(@"ContourButton addTapRunWithBlock");
//    }];
    [ContourButton addTarget:self action:@selector(ColorContourButtonEvent:) forControlEvents:UIControlEventTouchUpInside];
    [ContourButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(xsColorButton.mas_right).offset(10);
        make.top.equalTo(self.xsColorContourView.mas_top).offset(margin5);
        make.width.mas_equalTo(40);
        make.height.mas_equalTo(30);
    }];
    
    UILabel *horzontalLineLabel = [[UILabel alloc] init];
    horzontalLineLabel.backgroundColor = UIColor.whiteColor;
    [self.xsColorContourView addSubview:horzontalLineLabel];
    [horzontalLineLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(xsColorButton.mas_bottom).offset(margin5);
        make.left.equalTo(self.xsColorContourView.mas_left);
        make.right.equalTo(self.xsColorContourView.mas_right);
        make.height.mas_equalTo(1.0);
    }];
    
    
 
    UIView *xsColorContourContentView = [[UIView alloc] initWithFrame:CGRectMake(0, 55, self.xsColorContourView.width, 40)];
    xsColorContourContentView.backgroundColor = UIColor.clearColor;
    [self.xsColorContourView addSubview:xsColorContourContentView];
    
    
    // 颜色选项卡
    UIScrollView *xsColorContourContentView_colorScrV = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, xsColorContourContentView.width, 40)];
    xsColorContourContentView_colorScrV.backgroundColor = UIColor.clearColor;
    xsColorContourContentView_colorScrV.showsVerticalScrollIndicator = NO;
    xsColorContourContentView_colorScrV.showsHorizontalScrollIndicator = NO;
    [xsColorContourContentView addSubview:xsColorContourContentView_colorScrV];
    self.xsColorContourContentView_colorScrV = xsColorContourContentView_colorScrV;
    [self createxsColorContourContentView_colorScrVSubViews];
    
    
    // 描边选项卡
    UIScrollView *xsColorContourContentView_ContourScrV = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, xsColorContourContentView.width, 40)];
    xsColorContourContentView_ContourScrV.backgroundColor = UIColor.clearColor;
    xsColorContourContentView_ContourScrV.showsVerticalScrollIndicator = NO;
    xsColorContourContentView_ContourScrV.showsHorizontalScrollIndicator = NO;
    [xsColorContourContentView addSubview:xsColorContourContentView_ContourScrV];
    xsColorContourContentView_ContourScrV.hidden = YES;
    self.xsColorContourContentView_ContourScrV = xsColorContourContentView_ContourScrV;
    [self createxsColorContourContentView_ContourScrVSubViews];
}
#pragma mark 点击了颜色、描边
- (void)ColorContourButtonEvent:(UIButton *)sender{
    
    if(sender.tag==0){// 颜色
        self.xsColorContourContentView_colorScrV.hidden = NO;
        self.xsColorContourContentView_ContourScrV.hidden = YES;
        
        [self.xsColorContourLineView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.xsColorContourView.mas_left).offset(5);
        }];
        
        // 描边
        self.xsOutlineLabel.hidden = YES;
        self.xsOutlineView.hidden = YES;

        // 字号
        self.xsCharacterLabel.hidden = NO;
        self.xsCharacterView.hidden = NO;
    }
    else{// 描边
        self.xsColorContourContentView_colorScrV.hidden = YES;
        self.xsColorContourContentView_ContourScrV.hidden = NO;
        
        [self.xsColorContourLineView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.xsColorContourView.mas_left).offset(40+10+5);
        }];
        
        // 描边
        self.xsOutlineLabel.hidden = NO;
        self.xsOutlineView.hidden = NO;

        // 字号
        self.xsCharacterLabel.hidden = YES;
        self.xsCharacterView.hidden = YES;
    }
    
//    [self.xsColorContourLineView mas_updateConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(sender.mas_left).offset(5);
////        make.bottom.equalTo(xsColorButton.mas_bottom).offset(3);
////        make.width.mas_equalTo(30);
////        make.height.mas_equalTo(3);
//    }];
    
    
}
#pragma mark 描边选项卡的子view
- (void)createxsColorContourContentView_ContourScrVSubViews{
    
    //UIFont *btnFont = [UIFont systemFontOfSize:16];
    
    //NSArray *tempColorArr = @[UIColor.redColor,UIColor.redColor];
    
//    if(self.fontStyleDataMarray.count<=0){
//        return;
//    }
    for (UIView *tempItemView in self.xsColorContourContentView_ContourScrV.subviews) {
        [tempItemView removeFromSuperview];
    }
    
    NSArray *xs84ColorArr = [UIColor get84Color];
    
    UIButton *lastButton;
    // 添加按钮到滚动视图
    for (int i = 0; i < xs84ColorArr.count; i++) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        NSString *tempBtnColorStr = xs84ColorArr[i];
//        NSString *tempBtnColorStr = tempColorModel.outlineColour;
        
        
        CGFloat buttonW = 40;//[buttonTitleStr calculateWidth:btnFont withHeight:40]+25.0;
//        button.frame = CGRectMake(i * buttonW, 0, buttonW, 40);
        if(lastButton){
            button.frame = CGRectMake(CGRectGetMaxX(lastButton.frame), 0, buttonW, 40);
            
        }
        else{
            button.frame = CGRectMake(0, 0, buttonW, 40);
        }
        button.backgroundColor = [UIColor xsColorwithHexString:tempBtnColorStr Alpha:1.0];//xrandomColor;//UIColor.clearColor;//
        [button addTarget:self action:@selector(ContourScrVSubVButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
//        button.layer.cornerRadius = 4.0;
//        button.layer.masksToBounds = YES;
        [button setTag:i];
        [self.xsColorContourContentView_ContourScrV addSubview:button];
        lastButton = button;
    }

    self.xsColorContourContentView_ContourScrV.contentSize = CGSizeMake(CGRectGetMaxX(lastButton.frame)+5.0, 40);
}

#pragma mark 点击描边选项卡中的一项
- (void)ContourScrVSubVButtonClicked:(UIButton *)sender{
    
    NSLog(@"ContourScrVSubVButtonClicked");
    
    for (UIButton *tempButton in self.xsColorContourContentView_ContourScrV.subviews) {
        if([tempButton isKindOfClass:[UIButton class]]){
            if(tempButton.tag!=sender.tag){
                tempButton.layer.borderWidth = 0.0;
                tempButton.layer.borderColor = UIColor.clearColor.CGColor;
                tempButton.layer.cornerRadius = 0.0;
                tempButton.layer.masksToBounds = NO;
            }
            else{
                tempButton.layer.borderWidth = 1.0;
                tempButton.layer.borderColor = UIColor.whiteColor.CGColor;
                tempButton.layer.cornerRadius = 3.0;
                tempButton.layer.masksToBounds = YES;
            }
        }
    }
    NSArray *xs84ColorArr = [UIColor get84Color];
    
    if(sender.tag<xs84ColorArr.count){
        NSString *xsHexColorStr = xs84ColorArr[sender.tag];
        
        if([self.delegate respondsToSelector:@selector(xsTexViewTextContourEvent:)]){
            [self.delegate xsTexViewTextContourEvent:xsHexColorStr];
        }
    }
    
}

#pragma mark 颜色选项卡的子view
- (void)createxsColorContourContentView_colorScrVSubViews{
    
//    NSArray *tempColorArr = @[kColorRandom,kColorRandom,kColorRandom,kColorRandom,kColorRandom,kColorRandom,kColorRandom,kColorRandom,kColorRandom,kColorRandom,kColorRandom,kColorRandom,kColorRandom,kColorRandom,kColorRandom];
    
    NSArray *xs84ColorArr = [UIColor get84Color];
    
//    if(self.fontStyleDataMarray.count<=0){
//        return;
//    }
    
    for (UIView *tempItemView in self.xsColorContourContentView_colorScrV.subviews) {
        [tempItemView removeFromSuperview];
    }
    UIButton *lastButton;
    // 添加按钮到滚动视图
    for (int i = 0; i < xs84ColorArr.count; i++) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        
        NSString *tempBtnColorStr =xs84ColorArr[i];
        
//        NSString *tempBtnColorStr = tempFontModel.primaryColour;// tempColorArr[i];
        CGFloat buttonW = 40;//[buttonTitleStr calculateWidth:btnFont withHeight:40]+25.0;
//        button.frame = CGRectMake(i * buttonW, 0, buttonW, 40);
        if(lastButton){
            button.frame = CGRectMake(CGRectGetMaxX(lastButton.frame), 0, buttonW, 40);
            
        }
        else{
            button.frame = CGRectMake(0, 0, buttonW, 40);
        }
        button.backgroundColor = [UIColor xsColorwithHexString:tempBtnColorStr Alpha:1.0];//xrandomColor;//UIColor.clearColor;//
        [button addTarget:self action:@selector(colorScrVSubVButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
//        button.layer.cornerRadius = 4.0;
//        button.layer.masksToBounds = YES;
        [button setTag:i];
        [self.xsColorContourContentView_colorScrV addSubview:button];
        lastButton = button;
    }

    self.xsColorContourContentView_colorScrV.contentSize = CGSizeMake(CGRectGetMaxX(lastButton.frame)+5.0, 40);
}
#pragma mark 点击颜色选项卡中的子view
- (void)colorScrVSubVButtonClicked:(UIButton *)sender{
    
    for (UIButton *tempButton in self.xsColorContourContentView_colorScrV.subviews) {
        if([tempButton isKindOfClass:[UIButton class]]){
            if(tempButton.tag!=sender.tag){
                tempButton.layer.borderWidth = 0.0;
                tempButton.layer.borderColor = UIColor.clearColor.CGColor;
                tempButton.layer.cornerRadius = 0.0;
                tempButton.layer.masksToBounds = NO;
            }
            else{
                tempButton.layer.borderWidth = 1.0;
                tempButton.layer.borderColor = UIColor.whiteColor.CGColor;
                tempButton.layer.cornerRadius = 3.0;
                tempButton.layer.masksToBounds = YES;
            }
        }
    }
    
    NSArray *xs84ColorArr = [UIColor get84Color];
    
    if(sender.tag<xs84ColorArr.count){
        NSString *xsHexColorStr = xs84ColorArr[sender.tag];
        
        if([self.delegate respondsToSelector:@selector(xsTexViewTextColorEvent:)]){
            [self.delegate xsTexViewTextColorEvent:xsHexColorStr];
        }
    }
}


#pragma mark 获取文字的描边图片列表数据
- (void)getFontStyleListData{
    //
//    UILabel *tempL;
    //tempL.layer.borderWidth = ;
//    tempL.layer.borderColor
        XSWeakSelf;
    [self.fontStyleDataMarray removeAllObjects];
        
    xsFontStyleData *tempFontStryleModel = [xsFontStyleData new];
    tempFontStryleModel.isNotFont = YES;
    tempFontStryleModel.xsDefaultLocalImageStr = @"xsBossIPNotSelectFontIcon";
    tempFontStryleModel.backColour = @"";
    tempFontStryleModel.borderStyle = 0;
    tempFontStryleModel.outlineBorderWidth = 0;
    tempFontStryleModel.outlineColour = @"#FFFFFF";
    tempFontStryleModel.primaryColour = @"#FFFFFF";
    [self.fontStyleDataMarray addObject:tempFontStryleModel];
//
    
//        NSString *tempUrl = @"https://mall219.writemall.com/bossapi/ass/list";
    
    NSString *tempUrl = [NSString stringWithFormat:@"%@%@",API_BASEURL_BossIP,@"ass/list"];
        
    NSDictionary *pramerDict = @{};
        
        [[ZYFDataManager sharedInstance] GET:tempUrl dict:pramerDict succeed:^(id data) {
            
            NSLog(@"getFontStyleListData-pramerDict==%@--data==%@\n",pramerDict,data);
            
            NSDictionary *dictData = data;
            if([dictData isKindOfClass:[NSDictionary class]]){
                if([dictData[@"code"] isKindOfClass:[NSNumber class]]||[dictData[@"code"] isKindOfClass:[NSString class]]){
                    NSInteger codeInt = [dictData[@"code"] integerValue];
                    if(codeInt==200){
                        if([dictData[@"data"] isKindOfClass:[NSArray class]]){
                            NSArray *dataArr3  = dictData[@"data"];
                            
                            if(dataArr3.count>0){
                                for (int ii=0; ii<dataArr3.count; ii++) {
                                    NSDictionary *tempFinalDict = dataArr3[ii];
                                    xsFontStyleData *md = [xsFontStyleData yy_modelWithDictionary:tempFinalDict];
                                    md.outlineBorderWidth = 2;
                                    md.isNotFont = NO;
                                    if(md.borderStyle>0){
                                        md.outlineBorderWidth = md.borderStyle;
                                    }
//                                        if([tempFinalDict[@"id"] isKindOfClass:[NSNumber class]]||
//                                           [tempFinalDict[@"id"] isKindOfClass:[NSString class]]){
//                                           NSString *tempIdStr = [NSString stringWithFormat:@"%ld",[tempFinalDict[@"id"] integerValue]];
//                                            md.Id = [tempIdStr integerValue];
//                                        }
                                
                                    [weakSelf.fontStyleDataMarray addObject:md];
                                }
                                
                                dispatch_async(dispatch_get_main_queue(), ^{

                                    
                                    [weakSelf xsCreateFontTextBackgroundScrollViewWithArray:weakSelf.fontStyleDataMarray];
                                });
                            }
                        }
                    }
                }
            }
            
            
        } failure:^(NSDictionary *error) {
            NSLog(@"getFontStyleListData--error.description==%@\n",error.description);
        }];
}

#pragma mark 获取字体风格列表
- (void)getFontFamilyListData{
    //
        
        XSWeakSelf;
    
    [self.fontFamilyDataMarray removeAllObjects];
    xsFontFamilyData *tempFontFamilyModel = [xsFontFamilyData new];
    tempFontFamilyModel.isNotFont = YES;
    tempFontFamilyModel.xsDefaultLocalImageStr = @"xsBossIPNotSelectFontIcon";
    tempFontFamilyModel.fontNameLinux = @"";
    tempFontFamilyModel.fontNameWindows = @"";
    tempFontFamilyModel.Id = -1;
    tempFontFamilyModel.fontNameLinuxServer = @"";
    [self.fontFamilyDataMarray addObject:tempFontFamilyModel];
        
//        NSString *tempUrl = @"https://mall219.writemall.com/bossapi/ass/font";
    NSString *tempUrl = [NSString stringWithFormat:@"%@%@",API_BASEURL_BossIP,@"ass/font"];
        
    NSDictionary *pramerDict = @{};
        
        [[ZYFDataManager sharedInstance] GET:tempUrl dict:pramerDict succeed:^(id data) {
            
            NSLog(@"getFontFamilyListData-pramerDict==%@--data==%@\n",pramerDict,data);
            
            NSDictionary *dictData = data;
            if([dictData isKindOfClass:[NSDictionary class]]){
                if([dictData[@"code"] isKindOfClass:[NSNumber class]]||[dictData[@"code"] isKindOfClass:[NSString class]]){
                    NSInteger codeInt = [dictData[@"code"] integerValue];
                    if(codeInt==200){
                        if([dictData[@"data"] isKindOfClass:[NSArray class]]){
                            NSArray *dataArr3  = dictData[@"data"];

                            
                            if(dataArr3.count>0){
                                weakSelf.xsDownloadFontfamilyCout = dataArr3.count;
                                
                                dispatch_async(dispatch_get_main_queue(), ^{
                                    [MBProgressHUD showMessage:@"字体下载中..."];
                                });
                                for (int ii=0; ii<dataArr3.count; ii++) {
                                    NSDictionary *tempFinalDict = dataArr3[ii];
                                    xsFontFamilyData *md = [xsFontFamilyData yy_modelWithDictionary:tempFinalDict];
                                        if([tempFinalDict[@"id"] isKindOfClass:[NSNumber class]]||
                                           [tempFinalDict[@"id"] isKindOfClass:[NSString class]]){
                                           NSString *tempIdStr = [NSString stringWithFormat:@"%ld",[tempFinalDict[@"id"] integerValue]];
                                            md.Id = [tempIdStr integerValue];
                                        }
                                    md.isNotFont = NO;
                                    md.fontNameLinuxServer = md.fontNameLinux;
                                    
                                    [weakSelf.fontFamilyDataMarray addObject:md];
                                    
                                    if(!kStringIsEmpty(md.ossUrl)){
                                        [weakSelf xsDownloadFontFamilyWithUrl:md];
                                    }
                                }

                                [weakSelf xsCreateFontFamilyViewWithArray:weakSelf.fontFamilyDataMarray];
                            }
                        }
                    }
                }
            }
            
            
        } failure:^(NSDictionary *error) {
            NSLog(@"getFontFamilyListData--error.description==%@\n",error.description);
        }];
}

#pragma mark 下载字体
- (void)xsDownloadFontFamilyWithUrl:(xsFontFamilyData *)xsFontFamilyModel
{
    
    
    NSString *xsFontFamilyUrlString = xsFontFamilyModel.ossUrl;
    NSString *xsfontNameLinuxStr = xsFontFamilyModel.fontNameLinux;
    if(!kStringIsEmpty(xsfontNameLinuxStr)){
        
        //判断字体是否加载
        //在使用字体文件前最好是先判断字体是否已经被加载过了，判断方式如下：
        BOOL xsFontIsLoadToApp = [UIFont isFontDownloaded:xsfontNameLinuxStr];
        
        NSString *tempStr = [NSString stringWithFormat:@"xsFontIsLoadToApp-==%@",xsFontIsLoadToApp?@"YES":@"NO"];
        XSLogMethod2(tempStr)
        
        if(xsFontIsLoadToApp){
            
            self.xsDownloadFontfamilyCout = self.xsDownloadFontfamilyCout-1;
            if(self.xsDownloadFontfamilyCout<=0){
                XSWeakSelf;
                dispatch_async(dispatch_get_main_queue(), ^{
                    //[MBProgressHUD hideLoading];
                    [MBProgressHUD hideHUDForView:[MBProgressHUD defaultView] animated:NO];
                    [MBProgressHUD showSuccess:@"字体加载完成"];
                });
            }
            return;
        }
    }
    
    //
    
    NSFileManager *fileManager = [NSFileManager defaultManager]; //创建文件管理器
    //    NSString *tempPath = NSTemporaryDirectory();    //获得临时文件夹路径

    //写入沙盒Documents
    NSArray *pathsDocument = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [pathsDocument objectAtIndex:0];
    NSString *tempPath = [documentsDirectory stringByAppendingPathComponent:@"wqoplgdir/xsBossFontFamilyFold"];

    // 判断文件夹是否存在
    BOOL folderExists = [fileManager fileExistsAtPath:tempPath];
    // 如果文件夹不存在，就创建文件夹
    if (!folderExists) {
        // 创建文件夹
        NSError *error = nil;
        BOOL success = [fileManager createDirectoryAtPath:tempPath
                                withIntermediateDirectories:YES // 创建中间缺少的目录
                                                 attributes:nil
                                                      error:&error];
        if (!success) {
            // 处理错误
            NSLog(@"创建文件夹失败: %@", [error localizedDescription]);
        }
        else{
            folderExists = YES;
        }
    }


//    NSString *tempPath00 =  [NSString stringWithFormat:@"%@_%@.txt",fNameStr,timeLocal];//[NSString getCurrentFormatTimes]
//    NSString *tempFile = [tempPath stringByAppendingPathComponent:tempPath00]; //获得文件全路径
//    if (![fileManager fileExistsAtPath:tempFile]) {
//        [fileManager createFileAtPath:tempFile contents:nil attributes:nil];  //如果文件不存在就创建一个
//    }
//
//    NSString * tempstr = [NSString stringWithFormat:@"%@",contentString];
//
//    NSMutableData *writer = [[NSMutableData alloc] init];   //创建缓冲区
//    [writer appendData:[tempstr dataUsingEncoding:NSUTF8StringEncoding]]; //将数据写入缓冲区
//    [writer writeToFile:tempFile atomically:YES];   //将缓冲数据写入文件
    if(folderExists){
        NSLog(@"xsFontFamilyUrlString==%@\n",xsFontFamilyUrlString);
        NSLog(@"tempPath==%@\n",tempPath);
        
        //    //    NSString *filePath = @"path/to/your/file.txt";
        //        NSString *fileName = [filePath lastPathComponent];
        //        // 移除扩展名
        //        fileName = [fileName stringByDeletingPathExtension];
            
            NSString *tempDownLoadFileName = [xsFontFamilyUrlString lastPathComponent];
            BOOL isHaveFileData = xsFileExistsInDirectoryT(tempPath, tempDownLoadFileName);
        
            NSLog(@"isHaveFileData==%@\n",isHaveFileData?@"YES":@"NO");
            if(isHaveFileData){
                NSString *tempFontNamePathStr = [NSString stringWithFormat:@"%@/%@",tempPath,tempDownLoadFileName];
                NSString *xsCustFontNameStr =  [UIFont CXGetCustomFontNameWithPath:tempFontNamePathStr];
                xsFontFamilyModel.fontNameLinux = xsCustFontNameStr;
                
                self.xsDownloadFontfamilyCout = self.xsDownloadFontfamilyCout-1;
                if(self.xsDownloadFontfamilyCout<=0){

                    dispatch_async(dispatch_get_main_queue(), ^{
                        //[MBProgressHUD hideLoading];
                        [MBProgressHUD hideHUDForView:[MBProgressHUD defaultView] animated:NO];
                        [MBProgressHUD showSuccess:@"字体加载完成"];
                    });
                }
                return;
            }
            
        
        XSWeakSelf;
        [UIFont downloadZipFile:xsFontFamilyUrlString toPath:tempPath withResult:^(NSString * _Nonnull saveFileDataPathUrlString) {
            //NSString *xsCustFontFilePathString =
            
            
            NSString *xsCustFontNameString =  [UIFont CXGetCustomFontNameWithPath:saveFileDataPathUrlString];
            NSLog(@"xsCustFontNameString-xsCustFontNameString==%@\n",xsCustFontNameString);
            NSLog(@"DownDowxsCustFontNameString-fontNameLinux==%@\n",xsFontFamilyModel.fontNameLinux);
            xsFontFamilyModel.fontNameLinux = xsCustFontNameString;
            
            weakSelf.xsDownloadFontfamilyCout = weakSelf.xsDownloadFontfamilyCout-1;
            if(weakSelf.xsDownloadFontfamilyCout<=0){

                dispatch_async(dispatch_get_main_queue(), ^{
                    //[MBProgressHUD hideLoading];
                    [MBProgressHUD hideHUDForView:[MBProgressHUD defaultView] animated:NO];
                    [MBProgressHUD showSuccess:@"字体下载完成"];
                });
                
    //            //tempPath
    //           NSArray *xsCustFontArr = [UIFont CXGetCustomFontNameArrayWithPath:tempPath];
    //            NSLog(@"xsCustFontArr==%@\n",xsCustFontArr);
                
    //            int a = 10;
            }
        }];
        
        
    }
}
//{
//    
//    
//    NSString *xsFontFamilyUrlString = xsFontFamilyModel.ossUrl;
//    NSString *xsfontNameLinuxStr = xsFontFamilyModel.fontNameLinux;
//    if(!kStringIsEmpty(xsfontNameLinuxStr)){
//        
//        //判断字体是否加载
//        //在使用字体文件前最好是先判断字体是否已经被加载过了，判断方式如下：
//        BOOL xsFontIsLoadToApp = [UIFont isFontDownloaded:xsfontNameLinuxStr];
//        
//        NSString *tempStr = [NSString stringWithFormat:@"xsFontIsLoadToApp-==%@",xsFontIsLoadToApp?@"YES":@"NO"];
//        XSLogMethod2(tempStr)
//        
//        if(xsFontIsLoadToApp){
//            return;
//        }
//    }
//    
//    //
//    
//    NSFileManager *fileManager = [NSFileManager defaultManager]; //创建文件管理器
//    //    NSString *tempPath = NSTemporaryDirectory();    //获得临时文件夹路径
//
//    //写入沙盒Documents
//    NSArray *pathsDocument = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
//    NSString *documentsDirectory = [pathsDocument objectAtIndex:0];
//    NSString *tempPath = [documentsDirectory stringByAppendingPathComponent:@"wqoplgdir/xsBossFontFamilyFold"];
//
//    // 判断文件夹是否存在
//    BOOL folderExists = [fileManager fileExistsAtPath:tempPath];
//    // 如果文件夹不存在，就创建文件夹
//    if (!folderExists) {
//        // 创建文件夹
//        NSError *error = nil;
//        BOOL success = [fileManager createDirectoryAtPath:tempPath
//                                withIntermediateDirectories:YES // 创建中间缺少的目录
//                                                 attributes:nil
//                                                      error:&error];
//        if (!success) {
//            // 处理错误
//            NSLog(@"创建文件夹失败: %@", [error localizedDescription]);
//        }
//        else{
//            folderExists = YES;
//        }
//    }
//
//
////    NSString *tempPath00 =  [NSString stringWithFormat:@"%@_%@.txt",fNameStr,timeLocal];//[NSString getCurrentFormatTimes]
////    NSString *tempFile = [tempPath stringByAppendingPathComponent:tempPath00]; //获得文件全路径
////    if (![fileManager fileExistsAtPath:tempFile]) {
////        [fileManager createFileAtPath:tempFile contents:nil attributes:nil];  //如果文件不存在就创建一个
////    }
////
////    NSString * tempstr = [NSString stringWithFormat:@"%@",contentString];
////
////    NSMutableData *writer = [[NSMutableData alloc] init];   //创建缓冲区
////    [writer appendData:[tempstr dataUsingEncoding:NSUTF8StringEncoding]]; //将数据写入缓冲区
////    [writer writeToFile:tempFile atomically:YES];   //将缓冲数据写入文件
//    if(folderExists){
//        NSLog(@"xsFontFamilyUrlString==%@\n",xsFontFamilyUrlString);
//        NSLog(@"tempPath==%@\n",tempPath);
//        
//        //    //    NSString *filePath = @"path/to/your/file.txt";
//        //        NSString *fileName = [filePath lastPathComponent];
//        //        // 移除扩展名
//        //        fileName = [fileName stringByDeletingPathExtension];
//            
//            NSString *tempDownLoadFileName = [xsFontFamilyUrlString lastPathComponent];
//            BOOL isHaveFileData = xsFileExistsInDirectoryT(tempPath, tempDownLoadFileName);
//        
//            NSLog(@"isHaveFileData==%@\n",isHaveFileData?@"YES":@"NO");
//            if(isHaveFileData){
//                NSString *tempFontNamePathStr = [NSString stringWithFormat:@"%@/%@",tempPath,tempDownLoadFileName];
//                NSString *xsCustFontNameStr =  [UIFont CXGetCustomFontNameWithPath:tempFontNamePathStr];
//                xsFontFamilyModel.fontNameLinux = xsCustFontNameStr;
//                
//                self.xsDownloadFontfamilyCout = self.xsDownloadFontfamilyCout-1;
//                if(self.xsDownloadFontfamilyCout<=0){
//                    //XSWeakSelf;
//                    dispatch_async(dispatch_get_main_queue(), ^{
//                        
//                        [MBProgressHUD hideHUDForView:[MBProgressHUD defaultView] animated:NO];
//                        //[MBProgressHUD hideLoading];
//                        [MBProgressHUD showSuccess:@"字体加载完成"];
//                    });
//                }
//                return;
//            }
//            else{
//                XSWeakSelf;
//                [UIFont downloadZipFile:xsFontFamilyUrlString toPath:tempPath withResult:^(NSString * _Nonnull saveFileDataPathUrlString) {
//                    //NSString *xsCustFontFilePathString =
//                    
//                    NSString *xsCustFontNameString =  [UIFont CXGetCustomFontNameWithPath:saveFileDataPathUrlString];
//                    NSLog(@"xsCustFontNameString-xsCustFontNameString==%@\n",xsCustFontNameString);
//                    NSLog(@"DownDowxsCustFontNameString-fontNameLinux==%@\n",xsFontFamilyModel.fontNameLinux);
//                    xsFontFamilyModel.fontNameLinux = xsCustFontNameString;
//                    
//                    weakSelf.xsDownloadFontfamilyCout = weakSelf.xsDownloadFontfamilyCout-1;
//                    if(weakSelf.xsDownloadFontfamilyCout<=0){
//                        
//                        dispatch_async(dispatch_get_main_queue(), ^{
//                            //[MBProgressHUD hideLoading];
//                            [MBProgressHUD hideHUDForView:[MBProgressHUD defaultView] animated:NO];
//                            [MBProgressHUD showSuccess:@"字体下载完成"];
//                        });
//                        
//            //            //tempPath
//            //           NSArray *xsCustFontArr = [UIFont CXGetCustomFontNameArrayWithPath:tempPath];
//            //            NSLog(@"xsCustFontArr==%@\n",xsCustFontArr);
//                        
//                        int a = 10;
//                    }
//                }];
//
//            }
//            
//
//        
//    }
//}

BOOL xsFileExistsInDirectoryT(NSString *directoryPath, NSString *fileName) {
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSString *filePath = [directoryPath stringByAppendingPathComponent:fileName];
    return [fileManager fileExistsAtPath:filePath];
}

#pragma mark UITextFieldDelegate
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
    
    // 检查替换文本是否为换行符（Return 键产生的）
    // 注意：这里检查的是 "\n"，因为 Return 键在 `UITextView` 中通常产生换行符
    if ([string isEqualToString:@"\n"]) {
        // 在这里执行你想要的操作，比如提交表单
        NSLog(@"Return 键被点击了");
  
        [self.topInputTextFeild resignFirstResponder];

        if(self.TopToorBarbuttonsArray.count>=2){
            if([self.delegate respondsToSelector:@selector(xsTexTextfieldTextReturnKeyBeClickChange:)]){
                [self.delegate xsTexTextfieldTextReturnKeyBeClickChange:self.topInputTextFeild.text];//
                //            //self.topInputTextFeild.text = @"";
            }
        }
        
        
        // 如果你不希望文本视图插入换行符，可以返回 NO
        // 否则，返回 YES 允许替换发生
        return NO; // 或者 YES，取决于你的需求
    }
    return YES;
}

- (void)textFieldDidChangeSelection:(UITextField *)textField{
    
    
    NSLog(@"textFieldDidChangeSelection--textField.text==%@\n",textField.text);
    if([self.delegate respondsToSelector:@selector(xsTexTextfieldTextChange:)]){
        [self.delegate xsTexTextfieldTextChange:textField.text];
    }
}

- (void)xsTopInputTextFeildTextString:(NSString *)textStr{
    
    self.topInputTextFeild.text = textStr;
//[self.topInputTextFeild becomeFirstResponder];
}

- (void)xstopInputTextFeildresignFirstRespond{
    if([self.topInputTextFeild isFirstResponder]){
        [self.topInputTextFeild resignFirstResponder];
    }
}

- (void)xsTopInputTextFeildTextbecomeFirstResponder{
    [self.topInputTextFeild becomeFirstResponder];
}


@end


